package com.doit.demo01;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
@SuppressWarnings("all")
public class clientTCP {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("192.168.2.145", 10085);
        new Thread(new Runnable() { //读信息
            @Override
            public void run() {
                while (true){
                    try {
                        InputStream in = socket.getInputStream();
                        byte[] bytes = new byte[1024];
                        int len = in.read(bytes);
                        System.out.println(new String(bytes,0,len));
                    } catch (IOException e) {}
                }
            }
        }).start();
        while (true){
                OutputStream out  = socket.getOutputStream();
                out.write(new Scanner(System.in).next().getBytes());
            }



    }
}
